package com.mdd.admin.controller.client;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IClientCrmCluepoolService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.ClientCrmCluepoolCreateValidate;
import com.mdd.admin.validate.ClientCrmCluepoolUpdateValidate;
import com.mdd.admin.validate.ClientCrmCluepoolSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ClientCrmCluepoolListedVo;
import com.mdd.admin.vo.ClientCrmCluepoolDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/cluepool")
@Api(tags = "线索池zsgc管理")
public class ClientCrmCluepoolController {

    @Resource
    IClientCrmCluepoolService iClientCrmCluepoolService;

    @GetMapping("/list")
    @ApiOperation(value="线索池zsgc列表")
    public AjaxResult<PageResult<ClientCrmCluepoolListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated ClientCrmCluepoolSearchValidate searchValidate) {
        PageResult<ClientCrmCluepoolListedVo> list = iClientCrmCluepoolService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="线索池zsgc详情")
    public AjaxResult<ClientCrmCluepoolDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ClientCrmCluepoolDetailVo detail = iClientCrmCluepoolService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "线索池zsgc新增")
    @PostMapping("/add")
    @ApiOperation(value="线索池zsgc新增")
    public AjaxResult<Object> add(@Validated @RequestBody ClientCrmCluepoolCreateValidate createValidate) {
        iClientCrmCluepoolService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "线索池zsgc编辑")
    @PostMapping("/edit")
    @ApiOperation(value="线索池zsgc编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ClientCrmCluepoolUpdateValidate updateValidate) {
        iClientCrmCluepoolService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "线索池zsgc删除")
    @PostMapping("/del")
    @ApiOperation(value="线索池zsgc删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iClientCrmCluepoolService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
